package com.bawei.mall.product.sync;

import com.alibaba.fastjson2.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeWapPayResponse;

/**
 * @Author：liurui
 * @Package：com.bawei.mall.product.sync
 * @Project：mall_cloud
 * @name：PayTest
 */
public class PayTest {
    public static void main(String[] args) {
        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi-sandbox.dl.alipaydev.com/gateway.do",
                "9021000139609980",
                "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDw5/JGzKVLe74s1qhl3L3qJ7D7z+LLN1Qb3k77bWLYmEorlxK6lreHn1u3++iiN/wsqqYAQr8iqOBTkNwP9+UDYDXyHLJTeygPym+Bp+C3nUHqVb9Gw9V6QPnOWX83HyX6iMoLjhuSq4/4OODELqx8FbR5Le1qbEQgUVtdwLJnH0Rawb96aDV1WcIRoKF2eNulRqxmaFNdbsrN7cq/gdDJRPXaPKtHZiWoNO3ocUL539ZUavY2DcYElWh1Y5inwTnUnFc/nokg9spGOEX1Dtu9KSNW+D+gAA1CDC7OPJyfw3dz84QzL4s2A5whPSrl67ByTuUYNgaYtUrC0lrspS29AgMBAAECggEBALgmhcPrEXu29rOtzwI2kBIbDyYeTl5LSAcZk8SMZF/vYdsaW524MkkA3wqwDK9cHm9CbyyJ2TO0Ze5bMG0gcLZ46CPQHdzEquYPN9ejrZqOImHv9AwzDM+sNYiwTxeivtRZliDpG1itvprfV6l/iCg+KzvqiK6uXhFaP35WG8nI2Cpn/H6T+rdG0KZgJS8NNSSFEb88qejVTp8ncS0CHrrmQ0NkfHLM0/NzyR/Mp04ipT1GZTefp3zKp+yLrvUnZQ5eb5B+VbNLUUg8wYJaN6agFy+CdYOb0pbLRkBw6Z+Sw1gaRs+16cwxvsHjRm7l2fIZm8ktBBxJYnftmtYA7d0CgYEA/P6ro2RnC7j3h2ftLlB1rByuBd4y2MV1aaNKZNFaLGJ+uQRVH3fkNwrLNw2a2wQHWeSNuv0/GKWNecJh8IVMVEuuzZDwPbU4uU6Twcmrc6PXWEjrRsV23/iU32g8qJJnpxoWs8QGTE4aXj8JEI7UmyOZtn5WjfOJK2OWK8O+0QcCgYEA88SD673dBJRBsEFWttXvdbJLI60wQXCdejlcL/sWQ53HhPn2aDZWHpZCmpU1aDzDgI0OC6RMdNIasrdNCxZO4wBg9a3k92hnzMp1hSZq5zKhjrePJXRCx4LndLQZ/nbMVqEj1alyuzVM8zJLMudLnFDxcNWA6FxBBihBW1lDThsCgYAs3mHEZZ8c5h4IRrc62ow0DRYT9ldgOIzdQleET9jFPGarG4iZPyMbW++0gNYw96LyH2W/fwB8t4fCy2WhSZLC9HU5AfaJiyVXQAdWfBTLOoiLoMsRTx4JFMYaZRs07loxuZ/DHAXd7JAinN1XsW0lYof1ZKynGkT+i/frJRknawKBgQClKpDMCUAY2y9K8mqDxZ7TW3Pn/2/D1z8MUpMw+2rRc7V9VzRq1e4yGVOVk+W08/7vOiO7JZ6cRMPMNcCg84ON8XLA5AtQy1ARhVhtWGN0tWyb26nFEeoxbnPPMjyumuXHCLXUDlTrnai+22PyYJ9tkbaV4kPOrLtuJZZrA6dD4wKBgDU/CiKSUZRzxE48rxIMD4JG54LWJBCIrc5XG9F5E67gqTniq4SZpR47yXbbOVb/oFJIEqu80Qjylj+gqqIf+Jvt71ZMHWGliv+X9hdyf6nAKTDGkofGZZ/77xiE1+1VqmPr2GRZEiVATOZ26ksrkKPnTpiYgQKsk/K7y8Rlmnfs",
                "json",
                "UTF-8",
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8OfyRsylS3u+LNaoZdy96iew+8/iyzdUG95O+21i2JhKK5cSupa3h59bt/voojf8LKqmAEK/IqjgU5DcD/flA2A18hyyU3soD8pvgafgt51B6lW/RsPVekD5zll/Nx8l+ojKC44bkquP+DjgxC6sfBW0eS3tamxEIFFbXcCyZx9EWsG/emg1dVnCEaChdnjbpUasZmhTXW7Kze3Kv4HQyUT12jyrR2YlqDTt6HFC+d/WVGr2Ng3GBJVodWOYp8E51JxXP56JIPbKRjhF9Q7bvSkjVvg/oAANQgwuzjycn8N3c/OEMy+LNgOcIT0q5euwck7lGDYGmLVKwtJa7KUtvQIDAQAB",
                "RSA2");

        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
        //异步接收地址，仅支持http/https，公网可访问
        request.setNotifyUrl("");
        //同步跳转地址，仅支持http/https
        request.setReturnUrl("");
        /******必传参数******/
        JSONObject bizContent = new JSONObject();
        //商户订单号，商家自定义，保持唯一性
        bizContent.put("out_trade_no", "20210817010101004");
        //支付金额，最小值0.01元
        bizContent.put("total_amount", 0.01);
        //订单标题，不可使用特殊符号
        bizContent.put("subject", "测试商品");

        /******可选参数******/
        //手机网站支付默认传值QUICK_WAP_WAY
        bizContent.put("product_code", "QUICK_WAP_WAY");
        //bizContent.put("time_expire", "2022-08-01 22:00:00");

        //// 商品明细信息，按需传入
        //JSONArray goodsDetail = new JSONArray();
        //JSONObject goods1 = new JSONObject();
        //goods1.put("goods_id", "goodsNo1");
        //goods1.put("goods_name", "子商品1");
        //goods1.put("quantity", 1);
        //goods1.put("price", 0.01);
        //goodsDetail.add(goods1);
        //bizContent.put("goods_detail", goodsDetail);

        //// 扩展信息，按需传入
        //JSONObject extendParams = new JSONObject();
        //extendParams.put("sys_service_provider_id", "2088511833207846");
        //bizContent.put("extend_params", extendParams);

        request.setBizContent(bizContent.toString());
        AlipayTradeWapPayResponse response = null;
        try {
            response = alipayClient.pageExecute(request,"POST");
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
        // 如果需要返回GET请求，请使用
        // AlipayTradeWapPayResponse response = alipayClient.pageExecute(request,"GET");
        String pageRedirectionData = response.getBody();
        System.out.println(pageRedirectionData);

        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }
}
